import React, { Dispatch } from 'react';

/** 定义管理页面上下文 */
export interface IManageContext {
  dispatch: Dispatch<any>;
  curRes: Record<string, any>;
}

/** 初始化管理页面上下文 */
const init_manage_context: IManageContext = {
  dispatch: () => {},
  curRes: {},
};

/** 创建公告管理上下文 */
const VersionManageContext = React.createContext(init_manage_context);

/**
 * 定义新增和编辑上下文
 * @prefixCls 标签标记前缀
 * @dispatch 派发匹配
 * @curRes 当前资源
 * @leftSearchValue 左侧树搜索值
 */
export interface IUpdateContext {
  prefixCls: string;
  dispatch: Dispatch<any>;
  curRes: Record<string, any>;
  locationProps: Record<string, any>;
  leftVersionType: string;
  reloadVersionInfo: () => void;
  getVersionDetailData: Record<string, any>;
}

/** 初始化新增和编辑上下文 */
const init_update_context: IUpdateContext = {
  prefixCls: 'version-',
  dispatch: () => {},
  curRes: {},
  locationProps: {},
  leftVersionType: '',
  reloadVersionInfo: () => {},
  getVersionDetailData: {},
};

/** 创建版本新增和编辑上下文 */
const VersionUpdateContext = React.createContext<IUpdateContext>(
  init_update_context,
);

/**
 * 系统版本详情上下文
 */
export interface IDetailContext {
  prefixCls: string;
  curRes: Record<string, any>;
  reloadVersionInfo: () => void;
  locationProps: Record<string, any>;
  getVersionDetailLoading: boolean;
  getVersionDetailData: Record<string, any>;
}

/** 系统版本详情上下文 */
const init_detail_context: IDetailContext = {
  prefixCls: 'version-update',
  curRes: {},
  reloadVersionInfo: () => {},
  locationProps: {},
  getVersionDetailLoading: false,
  getVersionDetailData: {},
};

/**系统版本详情 */
const VersionDetailContext = React.createContext<IDetailContext>(
  init_detail_context,
);

export { VersionManageContext, VersionUpdateContext, VersionDetailContext };
